//
//  ZSY_DestinationListTableViewCell.m
//  zsy_BreadTrip
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZSY_DestinationListTableViewCell.h"
#import "ZSY_DestinationListCollectionViewCell.h"
#import "ZSY_DestinationModel.h"

@interface ZSY_DestinationListTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, retain) ZSY_DestinationListCollectionViewCell *cell;
@property (nonatomic, retain) ZSY_CollectionView *destinationCollectionView;

@end

@implementation ZSY_DestinationListTableViewCell

- (void)dealloc {
    [_allArray release];
    [_cell release];
    [_destinationCollectionView release];
    [_flowLayout release];
    [super dealloc];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)setAllArray:(NSMutableArray *)allArray {
    if (_allArray != allArray) {
        [_allArray release];
        _allArray = [allArray retain];
        
    }
    [self.destinationCollectionView reloadData];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
//    self.contentView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:243 / 255.0 blue:233 / 255.0 alpha:1];;

    
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.itemSize = CGSizeMake((WIDTH - 30) / 2, 180);
    self.flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    self.destinationCollectionView = [[ZSY_CollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 400) collectionViewLayout:_flowLayout];
    self.destinationCollectionView.backgroundColor = [UIColor clearColor];
    self.destinationCollectionView.delegate = self;
    self.destinationCollectionView.dataSource = self;
    [self.destinationCollectionView registerClass:[ZSY_DestinationListCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.contentView addSubview:_destinationCollectionView];
    
    [_destinationCollectionView release];
    [_flowLayout release];
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ZSY_DestinationListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.destination = [_allArray objectAtIndex:indexPath.row];
    return cell;
}
#pragma mark - 点击事件  进入详情
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    ZSY_DestinationModel *model = [_allArray objectAtIndex:indexPath.row];
    NSString *string = model.url;
    
    NSLog(@"  =-=-=-=-=  %@", string);
    [self.delegate pushToDetailView:string];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _allArray.count;
}

@end
